home *** CD-ROM | disk | FTP | other *** search
/ Adobe Graphics & Publishing SDK 1996 December / Adobe Graphics & Publishing SDK 1996 December.iso / mac / Photoshop 4.0 SDK r2 Mac / Examples / Selection / Shape / Common / Shape.c next >
Encoding:
C/C++ Source or Header  |  1996-10-09  |  2.8 KB  |  147 lines  |  [TEXT/CWIE]

  1. /*
  2.    File: Shape.c
  3.  
  4.    Copyright (c) 1996, Adobe Systems Incorporated.
  5.    All rights reserved.
  6. */
  7.  
  8. #if __MWERKS__
  9. #include <SetupA4.h> // A4-globals
  10. #include <A4Stuff.h> // A4-globals
  11. #endif
  12.  
  13. #if defined(THINK_C) || defined(__MWERKS__)
  14. #define ENTRYPOINT main
  15. #endif
  16.  
  17. #include "Shape.h"
  18.  
  19. Handle hDllInstance = NULL;
  20.  
  21. /*****************************************************************************/
  22.  
  23. void InitGlobals (GPtr globals);
  24. void DoExecute (GPtr globals);
  25.  
  26. /*****************************************************************************/
  27.  
  28. /* All calls to the plug-in module come through this routine. It must be
  29.    placed first in the resource. To achieve this, most development systems
  30.    require that this be the first routine in the source. */
  31.  
  32. #if MSWindows
  33.        void ENTRYPOINT (short selector,
  34.                         PISelectionParams *selectionParamBlock,
  35.                         long *data,
  36.                         short *result)                
  37. #else
  38. pascal void ENTRYPOINT (short selector,
  39.                         PISelectionParams *selectionParamBlock,
  40.                         long *data,
  41.                         short *result)                
  42. #endif
  43.     {
  44.     
  45.     Globals globalValues;
  46.     GPtr globals = &globalValues;
  47.     
  48.     #if __MWERKS__
  49.     EnterCodeResource(); // A4-globals
  50.     #endif
  51.     
  52.     if (!*data)
  53.         {
  54.         
  55.         InitGlobals (globals);
  56.  
  57.         *data = (long) NewHandle (sizeof (Globals));
  58.         
  59.         if (!*data)
  60.             {
  61.             *result = memFullErr;
  62.             return;
  63.             }
  64.             
  65.         ** (GHdl) *data = globalValues;
  66.         
  67.         }
  68.         
  69.     globalValues = ** (GHdl) *data;
  70.         
  71.     gStuff = selectionParamBlock;
  72.     gResult = noErr;
  73.    
  74.     switch (selector)
  75.     {
  76.         
  77.         case selectionSelectorAbout:
  78.             DoAbout (globals);
  79.             break;
  80.             
  81.         case selectionSelectorExecute:
  82.             DoExecute (globals);
  83.             break;
  84.             
  85.         default:
  86.             gResult = selectionBadParameters;
  87.     }
  88.         
  89.     *result = gResult;
  90.     ** (GHdl) *data = globalValues;
  91.  
  92.     #if __MWERKS__
  93.     ExitCodeResource(); // A4-globals
  94.     #endif
  95. }
  96.  
  97. /*****************************************************************************/
  98.  
  99. void InitGlobals (GPtr globals)
  100. {    
  101.     gWhatShape = iShapeTriangle;
  102.     gCreate = iCreateSelection;
  103.     gQueryForParameters = true;
  104. }    
  105.  
  106. /*****************************************************************************/
  107.  
  108. void DoExecute (GPtr globals)
  109. {
  110.     Boolean            doThis = true;
  111.     int32            size = 0; // DWORD int32 size;
  112.     Ptr                p = NULL; // LPVOID Ptr hPtr;
  113.  
  114.     gQueryForParameters = ReadScriptParams (globals);
  115.  
  116.  
  117.     if ( gQueryForParameters ) doThis = DoParameters (globals);
  118.  
  119.     if ( doThis )
  120.     {
  121.         p = PIGetResource (PathResource, (int32)(ResourceID+gWhatShape), &size);
  122.         if (p == NULL || size < 1)
  123.             {
  124.             gResult = -1;
  125.             return;
  126.             }
  127.             
  128.         gStuff->newPath = PINewHandle (size);
  129.         
  130.         if (gStuff->newPath == NULL)
  131.             {
  132.             gResult = memFullErr;
  133.             return;
  134.             }
  135.  
  136.         memcpy(*gStuff->newPath, p, size);
  137.         PIReleaseResource(p);
  138.  
  139.         /* look in gStuff->supportedTreatments for support for this next thang */
  140.         
  141.         gStuff->treatment = KeyToEnum(EnumToKey(gCreate,typeCreate),typePISel);
  142.  
  143.         WriteScriptParams (globals);
  144.     } // user cancelled or dialog err or silent
  145. }
  146.  
  147.